const util = require('../../utils/util.js')
Page({
  data: {
    name:"",
    current: 0,
    tabbar: [{
      icon: "home",
      text: "首页",
      size: 21
    }, {
      icon: "category",
      text: "分类",
      size: 24
    }, {
      icon: "cart",
      text: "购物车",
      size: 22
    }, {
      icon: "people",
      text: "我的",
      size: 24
    }],
    hotSearch: [
      "金毛",
      "狗粮",
      "猫砂"
    ],
    banner: [
      "1.jpg",
      "2.jpg",
      "3.jpg",
      "4.jpg",
      "5.jpg"
    ],
    productList: [],
    pageIndex: 1,
    loadding: false,
    pullUpOn: true
  },
  onLoad: function(options) {

    //let postData = { username:username,password:password}
    util.request("/app/index2.html", null, "GET", false,  false ).then((res) => {
      console.log(res)
      this.setData({
        productList: res.data,
        pageIndex: 1,
        pullUpOn: true,
        loadding: false
      })
    })
  },
  tabbarSwitch: function(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      current: index
    })
    switch(index){
      case 0:break;
      case 1:
        this.classify();
      break;
      case 2:
        wx.navigateTo({
          url: '/pages/shopcart/shopcart'
        })
      break;
      case 3:
        wx.navigateTo({
          url: '/pages/userInfo/userInfo'
        })  
      break;
      default:break;
    }
  },

  detail: function(event) {
    wx.navigateTo({
      url: '../productDetail/productDetail?id='+event.currentTarget.dataset.id
    })
  },
  coupon: function () {
    wx.navigateTo({
      url: '../mall-extend/coupon/coupon'
    })
  },
  classify: function() {
    wx.navigateTo({
      url: '/pages/navbar-2/navbar-2'
    })

  },
  more: function(e) {
    let key = e.currentTarget.dataset.key || "";
    wx.navigateTo({
      url: '../productList/productList?searchKey=' + key
    })

  },
  search: function(e) {
  
    wx.navigateTo({
      url: '../productList/productList?name=' + e.detail.value
    })
  }
})